﻿using System;
using System.Xml.Linq;
using Engine;
using Game;

namespace Test1
{
    public class Test1ButtonsPanelWidget : CanvasWidget
    {
        public ComponentMiner m_componentMiner;

        public ComponentHealth m_componentHealth;

        public bool YHLZ = false;

        public bool BS = false;

        public ComponentTest1 m_componentTest1;

        public ComponentTask m_componentTask;

        public BevelledButtonWidget m_button1;

        public BevelledButtonWidget m_button2;

        public BevelledButtonWidget m_button3;

        public BevelledButtonWidget m_button4;

        public BevelledButtonWidget m_button5;

        public BevelledButtonWidget m_button6;

        public BevelledButtonWidget m_button7;

        public BevelledButtonWidget m_button8;

        public BevelledButtonWidget m_button9;

        public BevelledButtonWidget m_button10;

        public Test1ButtonsPanelWidget(ComponentTest1 componentTest1)
        {
            m_componentMiner = componentTest1.Entity.FindComponent<ComponentMiner>();
            m_componentTest1 = componentTest1;
            m_componentTask = componentTest1.m_componentTask;
            m_componentHealth = componentTest1.Entity.FindComponent<ComponentHealth>();
            XElement node = ContentManager.Get<XElement>("Test1/Widgets/Test1ButtonsPanelWidget");
            LoadContents(this, node);
            m_button1 = Children.Find<BevelledButtonWidget>("Button1");
            m_button2 = Children.Find<BevelledButtonWidget>("Button2");
            m_button3 = Children.Find<BevelledButtonWidget>("Button3");
            m_button4 = Children.Find<BevelledButtonWidget>("Button4");
            m_button5 = Children.Find<BevelledButtonWidget>("Button5");
            m_button6 = Children.Find<BevelledButtonWidget>("Button6");
            m_button7 = Children.Find<BevelledButtonWidget>("Button7");
            m_button8 = Children.Find<BevelledButtonWidget>("Button8");
            m_button9 = Children.Find<BevelledButtonWidget>("Button9");
            m_button10 = Children.Find<BevelledButtonWidget>("Button10");
        }

        public override void Update()
        {
            if (m_button1.IsClicked)
            {
                string txt = "新来的迷失者，欢迎你！食品工艺是万象系列的第二核心。万象系列，起源于原作者清凝的理想之作：万象宇宙。所有万象系列的模组，都是万象宇宙的孩子。\n例如，食品工艺就是万象宇宙其中的一个玩法分支。\n\n2.万象系列模组是对万象宇宙的拆分。所以，万象系列的所有模组都不会和万象宇宙本体兼容，同样的，内容最完整的是万象宇宙，其他所有的分支都只是万象宇宙的一部分玩法。\n\n3.万象的拆分是为了更好的满足玩家们的需求，同时也保证了兼容性和性能。比如有的玩家只想玩食品工艺，有的玩家只喜欢万象的洞穴优化地形，等等。与此同时，万象宇宙本体对设备的性能要求略高，故作拆分。\n\n4.食品工艺拓展了原版的食物，加入了几十种食物，同时，还拓展了79种植物（目前只适配了蘑菇），更多生物：蜘蛛，僵尸等；食品工艺包括了Buff体系，炼药体系，轻工业。并且可以和诸多模组兼容。相信一定可以给您带来绝佳的游戏体验\n\n5.万象宇宙的原作者清凝因车祸于2024年1月17日去世。清凝希望我来把万象宇宙完成，我答应了。清凝她会永远活在她的万象宇宙，理想国度里。";
                Test1TextDialog dialog = new Test1TextDialog("模组介绍", txt, null);
                DialogsManager.ShowDialog(m_componentTest1.m_componentPlayer.GuiWidget, dialog);
            }

            if (m_button2.IsClicked)
            {
                Action action = delegate
                {
                    m_componentMiner.ComponentPlayer.ComponentGui.ModalPanelWidget = new HelpButtonsPanelWidget2(m_componentMiner, m_componentMiner.Inventory, m_componentMiner.ComponentPlayer, m_componentHealth);
                };
                Test1TextDialog dialog2 = new Test1TextDialog("模组教程", "这是食品工艺的模组基础教程，点击跳转", action);
                DialogsManager.ShowDialog(m_componentTest1.m_componentPlayer.GuiWidget, dialog2);
            }

            if (m_button3.IsClicked)
            {
                string txt2 = "手册丢了怎么办？重要的事情重复三遍。因为众所周知，哪怕开发者把教程做的再无微不至，也总有无脑的不看手册和教程，所以我特意放了两个按钮提醒玩家要看手册，以及手册丢了怎么办。\n\n2.游戏开始的时候，会给你一本手册。每次你重生的时候，会自动给你一本手册。\n\n3.手册可以用实体灵能和木棍直接合成。\n\n4.遇事不决多看手册！！！！！！作者已经尽力解答疑惑了，手册会持续更新。\n\n5.";
                Test1TextDialog dialog3 = new Test1TextDialog("手册丢了怎么办？", txt2, null);
                DialogsManager.ShowDialog(m_componentTest1.m_componentPlayer.GuiWidget, dialog3);
            }

            if (m_button4.IsClicked)
            {
                m_componentTest1.m_componentPlayer.ComponentGui.ModalPanelWidget = new XRecipeWidget();
            }

            if (m_button5.IsClicked)
            {
                if (m_componentTest1.isMusicPlay)
                {
                    m_componentTest1.isMusicPlay = false;
                }
                else
                {
                    m_componentTest1.isMusicPlay = true;
                }
            }

            if (m_button6.IsClicked)
            {
                m_componentTest1.m_componentPlayer.ComponentGui.ModalPanelWidget = new MCCGPurchaseWidget(m_componentTest1.m_componentPlayer.ComponentMiner);
            }

            if (m_button7.IsClicked)
            {
            }

            if (m_button8.IsClicked)
            {
            }

            if (m_button9.IsClicked)
            {
                m_componentTest1.m_componentPlayer.ComponentGui.ModalPanelWidget = new TaskWidget(m_componentTask);
            }

            if (m_button10.IsClicked)
            {
                m_componentTest1.DeveloperModeOn = !m_componentTest1.DeveloperModeOn;
                string text = "食品工艺：开发者模式已" + (m_componentTest1.DeveloperModeOn ? "开启" : "关闭");
                m_componentTest1.m_componentPlayer.ComponentGui.DisplaySmallMessage(text, Color.White, blinking: true, playNotificationSound: true);
            }

            Color centerColor = (m_componentTest1.DeveloperModeOn ? new Color(50, 150, 35) : new Color(181, 172, 154));
            Color bevelColor = (m_componentTest1.DeveloperModeOn ? new Color(50, 150, 35) : new Color(181, 172, 154));
            m_button10.CenterColor = centerColor;
            m_button10.BevelColor = bevelColor;
        }
    }
}